package com.easytrain.app;

import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.easytrain.app.ListViewPriceAdapter.ListItemView;

public class ListViewStationAdapter  extends BaseAdapter{
	private Context 					context;
	private JSONArray 					listItems;
	private LayoutInflater 				listContainer;
	private int 						itemViewResource;
	static class ListItemView{				
		public TextView station;
	 }  

	public ListViewStationAdapter(Context context, JSONArray data,int resource) {
		this.context = context;		
		this.listContainer = LayoutInflater.from(context);
		this.itemViewResource = resource;
		this.listItems = data;
	}
	
	public int getCount() {
		return listItems.length();
	}

	public Object getItem(int arg0) {
		return null;
	}

	public long getItemId(int arg0) {
		return 0;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		ListItemView  listItemView = null;
		
		if (convertView == null) {
			convertView = listContainer.inflate(this.itemViewResource, null);
			
			listItemView = new ListItemView();

			listItemView.station = (TextView)convertView.findViewById(R.id.station_name);

			convertView.setTag(listItemView);
		}else {
			listItemView = (ListItemView)convertView.getTag();
		}	
		try{
			String item = listItems.getString(position);
			listItemView.station.setText(item);
			
		}catch(Exception ex){
			
		}
		return convertView;
	}
}
